package com.mc.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.mc.model.Path;
import com.mc.model.Teacher;
import com.mc.model.newsandbulletin;
import com.mc.service.NewsandbulletService;
import com.mc.service.TeacherService;
import com.mc.utils.PathUtil;
import com.mc.utils.StringUtil;

@Controller
public class CommonController {

	/*@RequestMapping("/index")
	public ModelAndView Home(){
		ModelAndView mav = new ModelAndView();
		mav.setViewName("home");
		return mav;
	}*/
	private Path path = null;
	@Autowired private TeacherService teacherService;
	@Autowired private NewsandbulletService newsandbulletService;
	@RequestMapping("/frontPage/{path}")
	public ModelAndView showPage(@PathVariable("path")String path){
		ModelAndView mav = new ModelAndView();
		//System.out.println("path:"+StringUtil.getPageName(path));
		mav.setViewName("frontView/"+StringUtil.getPageName(path));
		return mav;
	}
/**
 * 
 * @param modelMap
 * @param view 需要展示的静态页面文件名
 * @return 静态页面
 */
	@RequestMapping("/view/static/{view}")
	public String static1(ModelMap modelMap,@PathVariable("view")String view)
	{
		String sMenu= "1";
		String mMenu = "2";
		if(view.contains("xkjs")){
			sMenu = "rcpy";
			mMenu = "xkjs";
		}else if(view.contains("bkpy")){
			sMenu = "rcpy";
			mMenu = "bkpy";
		}else if(view.contains("kxyj")){
			sMenu = "ScienceYJ";
			mMenu = "other";
		}else if(view.contains("djzc")){
			sMenu = "djzc";
			mMenu = "other";
		}
		else if(view.contains("zsjy")){
			sMenu = "zsjy";
			mMenu = "other";
		}else if(view.contains("xsgz")){
			sMenu = "studentwork";
			mMenu = "other";
		}else if(view.contains("zzjg")){
			sMenu = "AcademyGK";
			mMenu = "other";
		}
		else if(view.contains("xueyuanzuyin")){
			sMenu = "AcademyGK";
			mMenu = "xyzy";
		}
		else if(view.contains("xyld")){
			sMenu = "AcademyGK";
			mMenu = "xyzy";
		}
		else if(view.contains("shiyanzhongxin")){
			List<Teacher> ld1 = teacherService.selectbypositionadid(5, "主任");
			List<Teacher> ld2 = teacherService.selectbypositionadid(5, "副主任");
			List<Teacher> teachers = teacherService.selectbydid(5);
			modelMap.addAttribute("ld1", ld1);
			modelMap.addAttribute("ld2", ld2);
			modelMap.addAttribute("teachers", teachers);
			sMenu = "AcademyGK";
			mMenu = "syzx";
		}else if(view.contains("ShuoShiDian")){
			List<newsandbulletin> hotnews=newsandbulletService.selectHotNB("news");
			modelMap.addAttribute("hotnews", hotnews);
			List<newsandbulletin> recentNews = newsandbulletService.selectpNews(0, 5);
			modelMap.addAttribute("recentNews",recentNews);
			sMenu = "rcpy";
			mMenu = "ssd";
		}else if(view.contains("wyh")){
			sMenu = "AcademyGK";
			mMenu = "wyh";
		}

        path = PathUtil.setPathParams(new String[]{"PackageName:static","ViewName:"+view,"smenu:"+sMenu,"mmenu:"+mMenu});		       
		return PathUtil.returnStr(path,modelMap);	
	}
}
